import API from '../libs/resources'
// import router from '../router'
import axios from 'axios'
import 'url-search-params-polyfill'
// 登录
export const login = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.login, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取商品属性接口
export const getGoodsList = function (data, callback) {
  axios.get(API.getGoodsList, {
    params: data
  })
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取商品id获取商品列表
export const product = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.product, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取我的用户信息
export const getAccountAmount = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getAccountAmount, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取用户乐豆使用信息
export const rechargeRecord = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.rechargeRecord, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取用户乐豆使用信息
export const getBBlRecord = function (data, callback) {
  axios.get(API.getBBlRecord, {
    params: data
  })
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 查询我的购物车
export const queryMyCart = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.queryMyCart, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 
export const getClassifyInfos = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getClassifyInfos, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取首页banner
export const getBanners = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getBanners, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 加入购物车
export const joinCart = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.joinCart, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 移除已选商品
export const RemoveCart = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.RemoveCart, params)
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 获取支付charge 
export const createCharge = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.createCharge, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 申请成为vip会员 
export const memberByXF = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.memberByXF, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 申请成为vip会员 
export const WXsign = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.WXsign, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取收货地址列表
export const getAddressList = function (data, callback) {
  axios.get(API.getAddressList, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 添加收货地址
export const addAddress = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.addAddress, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 删除收货地址
export const delAddress = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.delAddress, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 设置默认收货地址
export const setDefaultAddress = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.setDefaultAddress, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 清选购物车已选商品
export const clearCart = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.clearCart, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取购物清单
export const getExchangeList = function (data, callback) {
  axios.get(API.getExchangeList, {
    params: data
  })
  .then(res => {
    return callback(res.data)
  })
  .catch(err => {
    return callback(err)
  })
}
// 收藏
export const joinMyFindOrFoot = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.joinMyFindOrFoot, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 查询我的收藏或者足迹
export const queryFindOrFoot = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.queryFindOrFoot, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取商品规格信息
export const getProductInfosBySkuId = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getProductInfosBySkuId, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 创建一个订单
export const createOrder = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.createOrder, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 根据订单号获取商品
export const getGoodsInfoByCode = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getGoodsInfoByCode, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取一个用户的订单信息
export const getOrderInfo = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getOrderInfo, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 购买单个商品
export const buyer = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.buyer, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取内容
export const getContext = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getContext, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取内容根据ID
export const getContextById = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getContextById, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取收益排行 -- 个人
export const getRewardRank = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getRewardRank, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取我的排行-- 个人
export const getMyRank = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getMyRank, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 发起众筹
export const ZCProduct = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.ZCProduct, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取正在进行的众筹活动
export const getLaunchZc = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getLaunchZc, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 帮助用户众筹
export const helpMaster = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.helpMaster, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取我的众筹
export const getMyProduct = function (data, callback) {
  axios.get(API.getMyProduct, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 根据众筹信息id获取帮助者名单
export const getHelpMe = function (data, callback) {
  axios.get(API.getHelpMe, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 根据众筹信息id获取信息
export const getInfoByZCInfo = function (data, callback) {
  axios.get(API.getInfoByZCInfo, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 领取已经筹满的商品
export const claimProduct = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.claimProduct, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取优惠券
export const getVoucher = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getVoucher, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 补齐差价
export const makeUpPrice = function (data, callback) {
  axios.get(API.makeUpPrice, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取积分记录
export const getIntegralRecord = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getIntegralRecord, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取处理状态和众筹类型
export const getZCState = function (data, callback) {
  axios.get(API.getZCState, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取打卡送礼商品
export const getDkslProduct = function (data, callback) {
  axios.get(API.getDkslProduct, {
    params: data
  })
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 我的打卡送礼
export const getMyDkProduct = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getMyDkProduct, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取历史打卡时间
export const getHistoryDkTime = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getHistoryDkTime, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 立即打卡
export const punchCard = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.punchCard, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 购买打卡商品
export const buyDkProduct = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.buyDkProduct, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 领取打卡商品
export const claimDkProduct = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.claimDkProduct, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 用户是否购买面膜
export const isBuyMask = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.isBuyMask, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 用户本周是否领取面膜
export const isThisWeekClaimMask = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.isThisWeekClaimMask, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 购买面膜
export const buyMask = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.buyMask, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 领取商品
export const claimMask = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.claimMask, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 用户是否这周领取面膜
export const isBuyThisWeek = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.isBuyThisWeek, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 获取用户领取面膜记录
export const getClaimMaskRecord = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.getClaimMaskRecord, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 判断是否该用户为渠道
export const isChannel = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.isChannel, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}
// 保存最后一次点击邀请链接的面膜邀请者
export const saveLastInviter = function (data, callback) {
  var params = new URLSearchParams()
  for (let item in data) {
    params.append(item, data[item])
  }
  axios.post(API.saveLastInviter, params)
    .then(res => {
      return callback(res.data)
    })
    .catch(err => {
      return callback(err)
    })
}